<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @property float $cost_price 原价
 * @property int $class_id 分类
 * @property int $id
 * @property int $sales 销量
 * @property string $content 商品详情
 * @property string $createtime
 * @property string $images 商品图片
 * @property string $name 商品名称
 * @property-read \app\model\SuperSpec[] $spec
 * @property-read \app\model\UserCollect $user_collect
 * @property-read mixed $images_text
 * @mixin \think\Model
 */
class Super extends Model
{
	protected $createTime = 'createtime';

	protected $append = [
		'images_text',
        'return_address'
	];

    function getReturnAddressAttr($value,$data)
    {
        $row = Config::getFieldByName('return_address', 'value');
        return json_decode($row);
    }
	
	function getImagesTextAttr($value,$data)
	{
		$value = $value ?? ($data['images'] ?? '');
		return $value?explode(',', $value):[];
	}
	
	function spec()
	{
		return $this->hasMany(SuperSpec::class,'super_id');
	}
	
	public function userCollect()
	{
		return $this->hasOne(UserCollect::class,'pro_id')->where(['type'=>2]);
	}
}
